package parts
{
        import flash.display.Shape;

        public class Particle1 extends Shape
        {
                private var velx:Number;
                private var vely:Number;

                public function Particle1()
                {
                        super();
                        init();
                }

                private function init():void
                {
                        //set a random position
                        x = Math.random()*280;
                        y = Math.random()*280;
                        //set a random velocity
                        velx = Math.random()*10-5;
                        vely = Math.random()*10-5;
                        //draw a square
                        graphics.beginFill(Math.random()*0xFFFFFF);
                        graphics.drawRect(0, 0, 20, 20);
                        graphics.endFill();
                }

                public function update():void
                {
                        //update position
                        x += velx;
                        y += vely;
                        //check if hitting left edge of swf
                        if (x<0)
                        {
                                x = -x;
                                velx = -velx;
                        }
                        //check if hitting right edge of swf
                        //right edge is 300, square is 20 wide, so check against 300-20=280
                        else if (x>280)
                        {
                                x = 280-(x-280);
                                velx = -velx;
                        }
                        //check if hitting top edge of swf
                        if (y<0)
                        {
                                y = -y;
                                vely = -vely;
                        }
                        //check if hitting bottom edge of swf
                        //bottom edge is 300, square is 20 high, so check against 300-20=280
                        else if (y>280)
                        {
                                y = 280-(y-280);
                                vely = -vely;
                        }
                }

        }
}